<?php

namespace app\common\model;

use think\Model;


class Address extends Model
{

    

    

    // 表名
    protected $name = 'address';
    
    // 自动写入时间戳字段
    protected $autoWriteTimestamp = 'int';

    // 定义时间戳字段名
    protected $createTime = 'create_time';
    protected $updateTime = 'update_time';
    protected $deleteTime = false;

    // 追加属性
    protected $append = [
		'status_text',
    ];
    
	const STATUS_NORMAL = 1;
	const STATUS_DELETE = 0;
    
	public static $statusList = [
		self::STATUS_NORMAL => '正常',
		self::STATUS_DELETE => '删除'
	];

	public function getStatusTextAttr($value, $data) {
		$value = $value ? : $data['status'];
		$list = self::$statusList;
		return $list[$value] ??'';
	}

	public function user() {
		return $this->belongsTo('user', 'user_id',  'id', '', 'left')->setEagerlyType(0);
	}
	
	public function province() {
		return $this->belongsTo('area', 'province_id',  'id', '', 'left')->setEagerlyType(0);
	}
	
	public function city() {
		return $this->belongsTo('area', 'city_id',  'id', '', 'left')->setEagerlyType(0);
	}
	
	public function area() {
		return $this->belongsTo('area', 'area_id',  'id', '', 'left')->setEagerlyType(0);
	}


}
